package com.alibaba.cloud.utils;

import java.io.Serializable;

import lombok.Data;


/**
 * To string.
 *
 * @return the java.lang. string
 */
@Data
public class Result implements Serializable {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -2779817544295899804L;

	/** The code. */
	private int code;

	/** The info. */
	private String info;

	/** The success. */
	// 通用的错误码
	public static Result SUCCESS = new Result(200, "success");
	
	/** The server error. */
	public static Result SERVER_ERROR = new Result(500, "服务端异常");
	
	/** The bind error. */
	public static Result BIND_ERROR = new Result(400, "参数校验异常：%s");

	/**
	 * Instantiates a new result.
	 */
	private Result() {
	}

	/**
	 * Instantiates a new result.
	 *
	 * @param code the code
	 * @param info the info
	 */
	private Result(int code, String info) {
		this.code = code;
		this.info = info;
	}

	/**
	 * Fill args.
	 *
	 * @param args the args
	 * @return the result
	 */
	public Result fillArgs(Object... args) {
		int code = this.code;
		String message = String.format(this.info, args);
		return new Result(code, message);
	}
}
